/*
 * @Author: wuqingchun
 * @Date: 2024-10-09 15:32:18
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-10-11 20:14:45
 */
#ifndef __NETPERF_UDP_H__
#define __NETPERF_UDP_H__

#include "netperf.h"
#include "netperf_socket.h"


class CNetperfUDPClient
{
    struct ClientStatistics
    {
        uint64_t ui64TxCnt;
        uint64_t ui64RxCnt;
        uint64_t ui64ErrCnt;
        int64_t i64MinRTT;
        int64_t i64MaxRTT;
        uint64_t ui64TotalRTT;
        int64_t i64MinTxCost;
        int64_t i64MaxTxCost;
        uint64_t ui64TotalTxCost;
        int64_t i64MinRxCost;
        int64_t i64MaxRxCost;
        uint64_t ui64TotalRxCost;
    };
public:
    CNetperfUDPClient(const NETPERF_PARAM_S& refParam);
    ~CNetperfUDPClient();

    int32_t Init();
    void Run();

    void ShowStatistics();
private:
    void __CalculateRTT(int64_t i64RTT);
    int64_t __GetTimeStamp();

    void __CalculateTxCost(int64_t i64Cost);
    void __CalculateRxCost(int64_t i64Cost);
private:
    const NETPERF_PARAM_S& m_refParam;
    int m_iSockFd = -1;
    ClientStatistics m_stStat {};
};

#endif //__NETPERF_UDP_H__